package NC89_字符串变形;

import java.util.Stack;

public class Solution {
    public String trans(String s, int n) {
        // write code here
        Stack<String> stack = new Stack<>();
        StringBuilder str = new StringBuilder();
        s = s + " ";
        for (int i = 0; i < n + 1; i++){
            if (s.charAt(i) == ' '){
                stack.push(str.toString());
                str = new StringBuilder();
            }else {
                if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z'){
                    str.append(Character.toUpperCase(s.charAt(i)));
                }else {
                    str.append(Character.toLowerCase(s.charAt(i)));
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        while (!stack.isEmpty()){
            sb.append(stack.pop());
            sb.append(' ');
        }
        sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }
}